/**
 * 
 * @authors Your Name (you@example.org)
 * @date    2018-08-23 09:03:57
 * @version $Id$
 */
 //自执行函数，判断是否已经登录，没有就会显示登陆注册链接
(function(){
    var nav=document.getElementById("nav");
    var navC=nav.children;
    if(document.cookie!=""){
    for(let i=0;i<navC.length;i++){
        if(navC[i].nodeName=="SPAN"){
            navC[i].remove();
            i=0;
        }
    }
    nav.innerHTML+=`<span class="fa fa-user-o fa-lg"><a onclick="clearAll()" href="">退出登录</a></span>`;
}
})()
//轮播图实现
 var imgs = ["../image/img1.jpg", "../image/img2.jpg", "../image/img3.jpg"];

    function fn(doWhat, id) {
        var currImg = document.getElementById(id);
        var currSrc = currImg.getAttribute("src");
        var index = imgs.indexOf(currSrc);
        //点击“上一张”或者“下一张”时分别执行相应操作
        if (doWhat == "before") {
            index -= 1;
            //当图片为第一张时
            if (index < 0) index = imgs.length - 1;
        }
        if (doWhat == "next") {
            index += 1;
            //当图片为后一张时
            if (index == imgs.length) index = 0;
        }
        currImg.setAttribute("src", imgs[index]);
    }
    //定时器实现自动轮播
    setInterval("fn('next','imgId')", 3000);
    //判断是否登陆，如果登陆，就能跳转到工具页面
    function change(){
        if(document.cookie.split("=")[1]=="yes"){
        location.replace("content.html");
    }
    //反之就需要先登录
        else{
            location.replace("login.html");
    }
    }
    //当点击退出登录时，会清除cookie值，再退出
function clearAll(){
    var date = new Date();
    var utc=date.toUTCString();
    window.document.cookie="state=yes;path=/;expires="+utc;
    var a=nav.getElementsByTagName("a")[0];
    a.setAttribute("href","login.html");

}
